package com.campus_information_portal.dao;

import com.campus_information_portal.entity.Project;
import com.campus_information_portal.entity.ProjectStudent;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * 社会实践dao层
 *
 * @author
 * @create 2018-05-24 14:12
 **/
public interface ProjectDao {
    /**
     * @Description 增加一个project
     * @author 20155870 杨润增
     * @methodName addProject
     * @param project
     * @returnType int
     * @create 2018/5/24 14:40
     **/
    @Insert("insert into project(project_id,term_id,stu_info_id,project_name,project_content,project_phonenum," +
            "project_start_date,project_endt_date,project_contact_people,project_platform,project_state)" +
            "values(NULL,#{termId},#{stuInfoId},#{projectName},#{projectContent},#{projectPhonenum}," +
            "#{projectStartDate},#{projectEndtDate},#{projectContactPeople},#{projectPlatform},#{projectState})")
    int addProject(Project project);

    /**
     * @Description
     * @author 20155870 杨润增
     * @methodName deleteProject
     * @param
     * @returnType
     * @create 2018/5/24 14:44
     **/
    @Delete("delete from project where project_id=#{projectId}")
    int deleteProject(@Param("projectId") int projectId);

    /**
     * @Description 修改申请状态
     * @author 20155870 杨润增
     * @methodName updateProject
     * @param projectId
     * @returnType
     * @create 2018/5/24 14:46
     **/
    @Update("update project " +
            "set project_state=#{projectState}" +
            " WHERE project_id=#{projectId}")
    int updateProject(@Param("projectId") int projectId,
                      @Param("projectState") int projectState);

    /**
     * @Description 查询我的项目
     * @author 20155870 杨润增
     * @methodName queryMyProject
     * @param
     * @returnType
     * @create 2018/5/24 14:50
     **/
    @Select("SELECT " +
            "project.*, student.stu_name," +
            "student.stu_sex," +
            "student.stu_num," +
            "student.academy_id," +
            "academy.academy_name," +
            "term.term_year," +
            "term.term_num " +
            "FROM " +
            "project," +
            "student," +
            "academy," +
            "term " +
            "WHERE " +
            "project.term_id = term.term_id " +
            "AND project.stu_info_id = student.stu_info_id " +
            "AND student.academy_id=academy.academy_id " +
            "AND student.stu_num=#{stuNum}")
    List<ProjectStudent> queryMyProject(@Param("stuNum") Integer stuNum);

    @Select("SELECT " +
            "project.*, student.stu_name," +
            "student.stu_sex," +
            "student.stu_num," +
            "student.academy_id," +
            "academy.academy_name," +
            "term.term_year," +
            "term.term_num " +
            "FROM " +
            "project," +
            "student," +
            "academy," +
            "term " +
            "WHERE " +
            "project.term_id = term.term_id " +
            "AND project.stu_info_id = student.stu_info_id " +
            "AND student.academy_id=academy.academy_id "
            )
    List<ProjectStudent> queryAllProject();

    /**
     * @Description 查询我的项目
     * @author 20155870 杨润增
     * @methodName queryMyProject
     * @param
     * @returnType
     * @create 2018/5/24 14:50
     **/
    @Select("SELECT " +
            "project.*, student.stu_name," +
            "student.stu_sex," +
            "student.stu_num," +
            "student.academy_id," +
            "academy.academy_name," +
            "term.term_year," +
            "term.term_num " +
            "FROM " +
            "project," +
            "student," +
            "academy," +
            "term " +
            "WHERE " +
            "project.term_id = term.term_id " +
            "AND project.stu_info_id = student.stu_info_id " +
            "AND student.academy_id=academy.academy_id " +
            "AND project_id=#{projectId}")
    ProjectStudent queryProjectById(@Param("projectId") Integer projectId);

    /**
     * @Description 根据stuInfoId和termId查询申请数
     * @author 20155870 杨润增
     * @methodName queryCountProject
     * @param stuInfoId,termId
     * @returnType int
     * @create 2018/5/24 20:36
     **/
    @Select("select count(*) from project where stu_info_id=#{stuInfoId} and term_id=#{termId} and project_state=1")
    int queryCountProject(@Param("stuInfoId") Integer stuInfoId, @Param("termId") Integer termId);

    /**
     * @Description 根据stuInfoId和termId查询申请数
     * @author 20155870 杨润增
     * @methodName queryCountProject
     * @param stuInfoId,termId
     * @returnType int
     * @create 2018/5/24 20:36
     **/
    @Select("select count(*) from project where stu_info_id=#{stuInfoId} and term_id=#{termId} and project_state=2")
    int canApplyProject(@Param("stuInfoId") Integer stuInfoId, @Param("termId") Integer termId);


    /**
     * @Description 更新一条project
     * @author 20155870 杨润增
     * @methodName updateNotice
     * @param
     * @returnType int
     * @create 2018/5/13 21:41
     **/
    @Update("update project " +
            "set project_name=#{projectName} ," +
            "project_content=#{projectContent} ," +
            "project_phonenum=#{projectPhonenum} ," +
            "project_start_date=#{projectStartDate} ," +
            "project_endt_date=#{projectEndtDate} ," +
            "project_contact_people=#{projectContactPeople} ," +
            "project_platform=#{projectPlatform} ," +
            "project_state=2 " +
            " WHERE project_id=#{projectId}")
    int updateMyProject(@Param("projectId") int projectId,
                        @Param("projectName") String projectName,
                        @Param("projectContent") String projectContent,
                        @Param("projectPhonenum") String projectPhonenum,
                        @Param("projectStartDate") Date projectStartDate,
                        @Param("projectEndtDate") Date projectEndtDate,
                        @Param("projectContactPeople") String projectContactPeople,
                        @Param("projectPlatform") String projectPlatform
    );


}
